<?php
	include_once 'isLogin.php';
	$infoc=new info();
	$table_name = "label";			//标签表
	$key_index = array('label_name');

	//添加
	if($_GET['action']=='add'){
		$arr=$_POST['values'];				//省市数组
	
		//插入数据
		$arr = array('label_name'=>$arr[0],);
		$commonc->insert($table_name,$arr);
		$id = $commonc->insert_id();

		if($id!=''){
			$return='<tr>
			<td> <input type="checkbox" name="checkbox" value="'.$id.'" /></td>
			<td value_id="'.$id.'">'.$arr['label_name'].'</td>
			<td class="xiugai">
			<a href="javascript:;" onclick="edit(\''.$id.'\',$(this),\'label_list.php?action=edit\')">修改</a>
			</td>
			</tr>';
			$arr=array('error'=>'0','content'=>$return);
		}else{
			$arr=array('error'=>'1','content'=>'添加失败');
		}
		echo json_encode($arr);
		exit();
	}
	
	//删除
	if($_GET['action']=='del'){
		echo $commonc->del($table_name,$_POST['id']);
		exit();
	}

	//修改
	if($_GET['action']=='edit'){
		$arr = array($key_index[$_POST['index']]=>$_POST['value']);
		echo $commonc->update($table_name,$arr,"id='".$_POST['value_id']."'");
		exit();
	}

	//得到所有内容
	if($_POST){
		$where=" AND i.label_name like '%".$_POST['title']."%'";
		$smarty->assign('search',$_POST);
	}
	
	// $sql = $table_name;
	// $row=$commonc->getList($sql,$sql,$key="*");
	$row=$infoc->label_list($where);
	$smarty->assign("row",$row['result']);
	$smarty->assign('page',$row['page']);
	
	$smarty->display("label_list.html");
?>